<?php

/**
 * @author Paweł Napieracz
 * @version 1.0
 */
class Form_Link {

    public static function generuj($link, $action) {
        $formularz = '<div class="form">';
        $Config = array(
            // Default fields size
            'size' => 35,
            // Default fields error css
            'css_error' => 'fields_error',
            'template_open' => '<div class="form_row">',
            'template_label' => '<label>|LABEL|</label>',
            'template_field' => '|FIELD|',
            'template_error' => '<BR><font class="error">- |ERROR|</font>',
            'template_close' => '</div>',
            'template_line' => "\n",
            'template_field_one' => '<div class="form_row">|LABEL||FIELD|</div>'
        );


        $Form = & new Form_AuriumForm($Config);
        $formularz .= $Form->OpenForm(array('m' => 'p',
                    'action' => $action));

        $id = array(
            'type' => 'hidden',
            'name' => 'id',
            'value' => isset($link['id']) ? $link['id'] : null);

        $nazwa = array('label' => 'Nazwa:',
            'type' => 'text',
            'name' => 'nazwa',
            'value' => htmlspecialchars(isset($_POST['nazwa']) ? $_POST['nazwa'] : $link['nazwa']));

        $url = array(
            'label' => 'Url:',
            'type' => 'text',
            'name' => 'url',
            'value' => htmlspecialchars(isset($_POST['url']) ? $_POST['url'] : $link['url']));

        $data_od = array(
            'label' => 'Data od:',
            'type' => 'text',
            'name' => 'data_od',
            'value' => htmlspecialchars(isset($_POST['data_od']) ? $_POST['data_od'] : $link['data_od']));
        
        $data_do = array(
            'label' => 'Data do:',
            'type' => 'text',
            'name' => 'data_do',
            'value' => htmlspecialchars(isset($_POST['data_do']) ? $_POST['data_do'] : $link['data_do']));
        
        $status = array(
            'label' => 'Status:',
            'type' => 'selectbox',
            'name' => 'status',
            'items' => array('1' => 'Aktywny', '2' => 'Nieaktywny', '0' => 'Usunięty'),
            'selected' => isset($_POST['status']) ? $_POST['status'] : isset ($link['status']) ? $link['status'] : 1,
        );

        $przyciski = array(
            'type' => 'button',
            'subtype' => array('submit', 'button'),
            'value' => array('Wyślij', 'Anuluj'),
            'extras' => array('', 'onClick="window.location = \'/cms/link/\';"'),
            'alone' => true
        );

        $Form->SetData(array($nazwa, $url, $data_od, $data_do, $status, $id));
        $formularz .= $Form->ShowFields();
        $formularz .= $Form->OneField($przyciski);
        $formularz .= $Form->CloseForm();
        $formularz .= '</div>';
        return $formularz;
    }

}

?>
